package com.pms.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.pms.entity.Ideacomment;
import com.pms.util.DBHelp;
import com.pms.util.RowMapper;

public class IdeaCommentDao {

	private DBHelp<Ideacomment> db=new DBHelp<Ideacomment>();
	
	public void save(Ideacomment icomment){
		String sql="INSERT INTO t_ideacomment (`content`,`t_user_useid`,`t_idea_id`) VALUE(?,?,?)";
		
		db.executeSQL(sql,icomment.getContent(),icomment.getUserid(),icomment.getIdeaid());
	}

	public List<Ideacomment> findByIdeaid(String idid) {
		
		String sql="SELECT t_ideacomment.id,t_ideacomment.content,t_ideacomment.createtime,t_user.username,t_ideacomment.t_idea_id FROM t_ideacomment LEFT JOIN t_user ON t_user.useid=t_ideacomment.t_user_useid WHERE t_ideacomment.t_idea_id=?";
		return db.executeQueryToList(sql, new RowMapper<Ideacomment>(){

				@Override
				public Ideacomment mapRow(ResultSet rs) throws SQLException {
					Ideacomment ic = new Ideacomment();
				    ic.setId(rs.getString("id"));
				    ic.setContent(rs.getString("content"));
				    ic.setCreatetime(rs.getString("createtime"));
				    ic.setIdeaid(rs.getString("t_idea_id"));
				    ic.setUsername(rs.getString("username"));
				    
					return ic;
				}
			}, idid);
		
		
	}

	public void del(String idid) {
		String sql="DELETE FROM t_ideacomment WHERE id=?";
		db.executeSQL(sql,idid);
		
	}
	
	
}
